#include <iostream>
#include <string>
#include "ProcessPool.hpp"

using namespace std;

void Usage(string proc)
{
    cout << "Usage fail\n" << endl;
} 
int main(int argc, char *argv[])
{
    if(argc != 2)
    {
        Usage(argv[0]);
        return 1;
    }
    int subprocessnum = stoi(argv[1]);

    srand((uint64_t)time(nullptr));

    // 创建子进程和管道
    ProcessPool *pro_ptr = new ProcessPool(subprocessnum);
    pro_ptr->CreateProcess(worker);

    int cnt = 6;
    while(cnt--)
    {
        int channel = pro_ptr->NextChannel();
        uint32_t code = NextTask();
        pro_ptr->Send(channel, code);
        sleep(1);
    }
    pro_ptr->KillAll();
    pro_ptr->Wait();
    sleep(100);
    delete pro_ptr;

    return 0;
}

